package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.condition;
import com.ymatou.iapi.godmch.parameter.getConditionLevelBean;
import com.ymatou.iapi.godmch.parameter.setConditionLevelBean;
import com.ymatou.iapi.godmch.parameter.setConditionMarkupConfigBean;
import com.ymatou.iapi.godmch.service.getConditionLevelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.markup_condition_level;
import com.ymttest.database.model.godmch.markup_condition_levelExample;
import com.ymttest.database.sqlwapper.godmch.markup_condition_levelWapper;
/**
*获取加价条件类型优先级
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getConditionLevel{
	private static getConditionLevelBean bean;
	private static getConditionLevelCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取加价条件类型优先级");
	}

	@Before
	public void caseUp() {
		bean=new getConditionLevelBean();
		call=new getConditionLevelCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConditionLevel_001() {
		Logger.start(true,"获取加价条件类型优先级-一条类型-返回成功");
		try {
			
			setConditionLevelBean levelBean=GodmchManageCallService.initSetConditionLevelBean();
			GodmchManageCallService.setConditionLevel(levelBean);
			
			bean.setAgentId(levelBean.getAgentId());
			bean.setSupplierId(levelBean.getSupplierId());
			call.setData(bean);
			call.callService();			
			
		   markup_condition_levelWapper markupConfig=new markup_condition_levelWapper();
		   markup_condition_levelExample example=new markup_condition_levelExample();
		   example.createCriteria().andAgent_idEqualTo(bean.getAgentId()).andSupplier_idEqualTo(bean.getSupplierId());
		   markup_condition_level level=markupConfig.selectByExample(example).get(0);
				
		   Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		 
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConditionLevel_002() {
		Logger.start(true,"获取加价条件类型优先级-设置两条类型-返回成功");
		try {
			setConditionLevelBean levelBean=GodmchManageCallService.initSetConditionLevelBean();
		    List<condition> lst=new ArrayList<condition>();
		    condition con=new condition();
		    con.setConditionType(5);
		    con.setConditionLevel(8);
		    lst.add(con);
		    
		    con=new condition();
		    con.setConditionType(2);
		    con.setConditionLevel(9);
		    lst.add(con);
		    levelBean.setList(lst);
	   		
			GodmchManageCallService.setConditionLevel(levelBean);
			
			bean.setAgentId(levelBean.getAgentId());
			bean.setSupplierId(levelBean.getSupplierId());
			call.setData(bean);
			call.callService();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConditionLevel_002_2() {
		Logger.start(true,"获取加价条件类型优先级-没有设置优先-返回空");
		try {
			setConditionLevelBean bean=new setConditionLevelBean();
			 Integer agentId=GodmchManageCallService.createAgent();
	         Integer supplierId=GodmchManageCallService.createApplySupplier().getSupplierId();
				//新增
	         setConditionMarkupConfigBean setBean=GodmchManageCallService.initSetConditionMarkupConfig(agentId,supplierId);
	         GodmchManageCallService.setConditionMarkupConfigCall(setBean);
	         
			bean.setAgentId(setBean.getAgentId());
			bean.setSupplierId(setBean.getSupplierId());
			call.setData(bean);
			call.callService();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConditionLevel_003() {
		Logger.start(true,"获取加价条件类型优先级-代理商id为空-返回失败");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getConditionLevel_004() {
		Logger.start(true,"获取加价条件类型优先级-供货商id为空-返回失败");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}